<?php

namespace App\Http\Controllers;

use App\Models\Master;
use App\Models\Video;
use Illuminate\Http\Request;

class FrontController extends Controller
{
    /*
     * 前台首页
     */
    public function index(){
        $now_time= time();
        $now_date= date('Y-m-d H:i:s',$now_time);
        $oVideos=Video::where('type','=',0)->orderby('start_at','desc')->get();
        $qVideo=Video::where('start_at', '>', $now_date)->where('type','=',1)->orderby('start_at')->get();
        $zVideo=Video::where('start_at', '<=', $now_date)->where('end_at', '>', $now_date)->where('type','=',1)->orderby('start_at')->get();
        return view('front.index')->with('qVideo',$qVideo)->with('zVideo',$zVideo)->with('oVideos',$oVideos);
    }

    public function master()
    {
        $oMasters=Master::orderby('id','desc')->paginate(3);
        return view('front.master')->with('oMasters',$oMasters);
    }
    public function masterlecture()
    {
        $now_time= time();
        $now_date= date('Y-m-d H:i:s',$now_time);
        $oVideos=Video::where('type','=',0)->orderby('start_at','desc')->get();
        $qVideo=Video::where('start_at', '>', $now_date)->where('type','=',1)->orderby('start_at')->get();
        $zVideo=Video::where('start_at', '<=', $now_date)->where('end_at', '>', $now_date)->where('type','=',1)->orderby('start_at')->get();
        return view('front.masterlecture')->with('qVideo',$qVideo)->with('zVideo',$zVideo)->with('oVideos',$oVideos);
    }
    public function mastershow($id)
    {
        $master=Master::find($id);
        return view('front.mastershow')->with('master',$master);
    }
    public function video()
    {
        $videos = Video::orderby('id')->paginate(6);
        return view('front.video')->with('videos',$videos);
    }

    public function videoshow($id)
    {
        $oVideo=Video::find($id);
        $oVideos=Video::where('type','=','0')->where('id','!=',$id)->orderby('id','desc')->get();
        return view('front.videoshow')->with('oVideo',$oVideo)->with('oVideos',$oVideos);
    }

}
